package com.ofcoder.tool.swagger;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author: yuanyuan.liu
 * @date: 2020/6/11 18:28
 */
@Component
@ConfigurationProperties(prefix = "tool.swagger")
public class SwaggerProperty {
    private boolean enable = true;
    private String basePackage;
    private Contact contact;
    private String title;
    private String description;
    private String version;
    private List<String> groups = new ArrayList<>();

    public static class Contact {
        private String name;
        private String url;
        private String email;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Contact contact = (Contact) o;
            return Objects.equals(name, contact.name) &&
                    Objects.equals(url, contact.url) &&
                    Objects.equals(email, contact.email);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name, url, email);
        }

        @Override
        public String toString() {
            return "Contact{" +
                    "name='" + name + '\'' +
                    ", url='" + url + '\'' +
                    ", email='" + email + '\'' +
                    '}';
        }
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public String getBasePackage() {
        return basePackage;
    }

    public void setBasePackage(String basePackage) {
        this.basePackage = basePackage;
    }

    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public List<String> getGroups() {
        return groups;
    }

    public void setGroups(List<String> groups) {
        this.groups = groups;
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SwaggerProperty that = (SwaggerProperty) o;
        return enable == that.enable &&
                Objects.equals(basePackage, that.basePackage) &&
                Objects.equals(contact, that.contact) &&
                Objects.equals(title, that.title) &&
                Objects.equals(description, that.description) &&
                Objects.equals(version, that.version) &&
                Objects.equals(groups, that.groups);
    }

    @Override
    public int hashCode() {
        return Objects.hash(enable, basePackage, contact, title, description, version, groups);
    }

    @Override
    public String toString() {
        return "SwaggerProperty{" +
                "enable=" + enable +
                ", bastPackage='" + basePackage + '\'' +
                ", contact=" + contact +
                ", title='" + title + '\'' +
                ", description='" + description + '\'' +
                ", version='" + version + '\'' +
                ", groups=" + groups +
                '}';
    }
}
